<script type="text/javascript">
//存储ajax响应数据
var obj;
function findUserName(){
	var username = document.getElementById('name').value;

	var ajax = new XMLHttpRequest();
	//var obj ;
	ajax.onreadystatechange=function(){
		if (ajax.readyState===4&&ajax.status===200){
			obj = ajax.responseText;
			if(obj!==""){
				document.getElementById('element').innerHTML = "用户已存在";
			}else {
				document.getElementById('element').innerHTML = "";
			}
		}

	}
	ajax.open('get','manager!selectUser?username='+username);
	ajax.send(null);
}
$(function() {
	$("#fm").submit(function(){
		if($("#name").val()===""){
			new $.zui.Messager('输入用户名不能为空！', {
				icon: 'cloud-upload',// 定义消息图标
				time:'1000'
			}).show();
			return false;
		}else return obj === "";

	})
});
</script>
<style>
	.addUser{
		margin: 0 30px 30px 30px;
	}
	#name{width: 200px;}
</style>
<!-- 对话框HTML 添加新用户	-->
<div class="modal fade" id="addUser">
  <div class="modal-dialog" style="width: 380px;">
    <div class="modal-content">
      <div class="addUser" >
      	<h2><i>添加新用户</i></h2>
      	<hr/>
      	<h4><i>输入所需添加用户名</i></h4>
      	<form action="manager!addUser" method="post" id="fm">
      	  	<div class="form-group" style="width: 250px;">
			    <input type="text" class="form-control" id="name" name="username" 
			    	placeholder="用户名" oninput="findUserName()"/>
				<span id="element" style="color: red;font-weight: bold;"></span>
			  </div>
		 	<div class="add-btn">
		  		<input type="submit" value="添加" class="btn"/>
				<a class="btn" href="manager!showAllUser">取消</a>
		  	</div>
		 </form>
      	</div>
      </div>
    </div>
  </div>
    	<!-- 对话框HTML 添加新用户	结束-->